/**
 * 
 */
package edu.umd.clip.lm.model.training;

import edu.umd.clip.lm.util.CountDistribution;


/**
 * @author Denis Filimonov <den@cs.umd.edu>
 *
 */
public abstract class SmoothingDataStorage {
	public static class Key {
		final int clusterid;
		final byte dataid;
		/**
		 * @param clusterid
		 * @param dataid
		 */
		public Key(int clusterid, byte dataid) {
			this.clusterid = clusterid;
			this.dataid = dataid;
		}
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + clusterid;
			result = prime * result + dataid;
			return result;
		}
		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (!(obj instanceof Key))
				return false;
			Key other = (Key) obj;
			return clusterid == other.clusterid && dataid == other.dataid;
		}
		@Override
		public String toString() {
			return "Key [clusterid=" + clusterid + ", dataid=" + dataid + "]";
		}
		public int getClusterid() {
			return clusterid;
		}
		public byte getDataid() {
			return dataid;
		}
	}
	
	public abstract CountDistribution getDistribution(Key key);
	
	public CountDistribution getDistribution(int clusterid, byte dataid) {
		return getDistribution(new Key(clusterid, dataid));
	}
	
	public abstract void putDistribution(Key key, CountDistribution dist);
	
	public void putDistribution(int clusterid, byte dataid, CountDistribution dist) {
		putDistribution(new Key(clusterid, dataid), dist);
	}
	
	public abstract void sync();
}
